package mhserver;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class MulticastSocketHandler {

	private static final int	PORT	= 5000;
	private MulticastSocket		sock;
	private InetAddress			address;

	public MulticastSocketHandler(String addr) {
		try {
			this.sock = new MulticastSocket(PORT);
			this.address = InetAddress.getByName(addr);
			this.sock.joinGroup(this.address);
		} catch (IOException e) {

			e.printStackTrace();
		}
	}

	public void send(String message) {
		byte[] buffer = new byte[65535];
		try {
			while (true) {
				DatagramPacket packet = new DatagramPacket(buffer, buffer.length, this.address, PORT);
				buffer = message.getBytes();
				this.sock.send(packet);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
